package cn.wellcare.api.user;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.wellcare.api.AuthorityBase;
import cn.wellcare.constant.BaseParam;
import cn.wellcare.constant.Constants;
import cn.wellcare.exception.BusinessException;
import cn.wellcare.pojo.CommonResponse;
import cn.wellcare.service.SystemUsersService;

@Controller
@RequestMapping(value = Constants.API_USER)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class CommonUserInfo extends AuthorityBase {

	@Resource
	private SystemUsersService systemUsersService;

	@Override
	protected void setParams(Map<String, Object> param) {
		super.setParams(param);

	}

	@RequestMapping(value = "getUserByName")
	@ResponseBody
	public CommonResponse<?> getMenuPermit(@RequestParam Map<String, Object> param) {
		try {
			Assert.notNull(param.get(BaseParam.USER_NAME));

			// 1.获取用户角色权限
			result = systemUsersService.getByLoginName((String) param.get(BaseParam.USER_NAME));
			if (!result.getSuccess()) {
				if (Constants.SERVICE_RESULT_CODE_SYSERROR.equals(result.getMsgCode())) {
					throw new RuntimeException(result.getMsgInfo());
				} else {
					throw new BusinessException(result.getMsgInfo());
				}
			}
			// 2.结果
			result.setHasPermit(true);
		} catch (Exception e) {
			requestFail(e);
		}
		setRequestURI(param);
		return result;
	}


}
